package by.gravity.web.services;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import by.gravity.web.util.StringUtil;

public class GroupServlet extends CommonServlet {

	private static final long serialVersionUID = 2798278431698144769L;

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		super.doGet(request, response);
		String specialityName = getSpecialityName(request);
		String kursName = getKursName(request);

		if (StringUtil.isEmpty(specialityName) || StringUtil.isEmpty(kursName)) {
			return;
		}

		PrintWriter writer = response.getWriter();

		try {
			writer.print(getProvider().getGroupsList(specialityName, kursName));
		} catch (InstantiationException | IllegalAccessException | ClassNotFoundException | SQLException e) {
			printExeption(writer, e);
		}
	}

}
